<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" value="选择" id="btn">
    <br>
    <select id="subject">
        <option>英语</option>
        <option>语文</option>
        <option>数学</option>
        <option>化学</option>
        <option>生物</option>
        <option>物理</option>
    </select>
    <script>
        // 获取元素
        var btn = document.getElementById("btn");
        var subject = document.getElementById("subject");
        var subs = subject.getElementsByTagName("option");
        // 点击按钮事件
        btn.onclick = function(){
            // 定义变量存储数组随机下标
            var n = Math.floor(Math.random() * subs.length);
            console.log(n);
            subs[n].selected = true;
        }
    </script>
</body>
</html>